/*
 * evento randomize para arrays. Desordena todos sus elementos.
 */
/*
 * evento randomize para arrays. Desordena todos sus elementos.
 */
Array.prototype.randomize = function () {
	// Array temporal, copia del original.
	var $arrTmp = new Array (this.length);
	var $arrTmpIndRnd = new Array (this.length);
	var $arrIndRnd = new Array (this.length);

	for (var $i = 0; $i < $arrTmpIndRnd.length; $i++) $arrTmpIndRnd[$i]=$i;
	$arrTmp = this.copy ();

	// Quitar y poner (los grosos le dice 'Pick and Drop')
	for (var i = 0; $arrTmp.length; i ++) {
		var rndNum = $random (0, ($arrTmp.length -1));
		this[i] = $arrTmp[rndNum];
		$arrIndRnd[i] = $arrTmpIndRnd[rndNum];
		
		$arrTmp.splice (rndNum, 1);
		$arrTmpIndRnd.splice (rndNum, 1);
	};
	return $arrIndRnd;			
}

/*
 * setCircular. Nos da coordenadas de n elementos sobre una elipse de ancho y alto.
 */
Array.prototype.setCircular = function (options) {

	options.alphaIni = (options.alphaIni) ? (2 * Math.PI/360)*options.alphaIni : 0;
	options.alphaFin = (options.alphaFin) ? (2 * Math.PI/360)*options.alphaFin : 2 * Math.PI;
	
	var angulo = (options.alphaFin - options.alphaIni) / this.length;
	for (var iE = 0, el = this[iE]; iE < this.length; iE ++) {
		var alfa = angulo * iE + options.alphaIni;

		this[iE] = {
			x: (Math.sin(alfa) * (options.width / 2) + options.left).toInt(),
			y: (Math.cos(alfa) * (-options.height / 2) + options.top).toInt()
		}
	};
};


/*
 * Bloquea el contenido del contenido principal de la actividad 'content'.
 * Lo hace avisualizando un div 'block'.
 */
function contentBlock (estado) {
	switch (estado) {
		case 0:
			$('block').setStyle ('display', 'none');
		break;

		case 1:
			$('block').setStyle ('display', 'block');
		break;
	};
};


/*
 * Funcion de configuracion del menu de navegacion.
 * funtion initMenu
 */
var initMenu = function (options) {
	window.addEvent ('domready', function () {
		// Slide de Info de actividades.
		var infoSlide = new Fx.Slide('infoWin');
		infoSlide.hide();
		
		$('infoWin').addEvent ('mousedown', function (e) {
			e = new Event(e);
			infoSlide.slideOut();
			e.stop();
		});
		
		// btns son los botones de todo la barra de Menu. Es MUY importante le orden de los nodos DOM en la estructura html
		var $btns = $$('#menuBar div div');

		// Agregamos eventos
		$btns.each (function ($btn, $iB) {

			if ($btn.getProperty ('action') != null) {
				$btn.addEvents ({
					'mouseenter': function () {$btn.setStyle('background-position', $iB*(-60).toString() + 'px -60px')},
					'mouseleave': function () {$btn.setStyle('background-position', $iB*(-60).toString() + 'px top')},
					'mousedown': function () {$btn.setStyle('background-position', $iB*(-60).toString() + 'px -120px')},
					'mouseup': function () {$btn.setStyle('background-position', $iB*(-60).toString() + 'px top')},
					'click': function (e) {
						var $arrAction2Btn = $btn.getProperty('action').split(':');

						// Restart
						if ($arrAction2Btn[0] == 'restart') {
							initAct();
						};
						
						// Check
						if ($arrAction2Btn[0] == 'check') {
							checkAct();
						};
						
						// Info
						if ($arrAction2Btn[0] == 'info') {
							e = new Event(e);
							infoSlide.toggle();
							e.stop();
						};
						
						// Home
						if ($arrAction2Btn[0] == 'home') {
							var link = (document.location).toString ();
							var arrlink = link.split ('/');
							var letraAct = arrlink[arrlink.length-1].substring (3, 4);
							var menuAct = link.substr (0, link.length - arrlink[(arrlink.length)-1].length - arrlink[(arrlink.length)-2].length - 1) + 'menu' + letraAct + '.html';
							document.location = menuAct;
						};
						
						// Link
						if ($arrAction2Btn[0] == 'link') {
							var link = (document.location).toString ();
							var arrlink = link.split ('/');
							var letraNext = String.fromCharCode (arrlink[arrlink.length-1].charCodeAt(5) + 1);
							var actNext = $arrAction2Btn[1];
							var linkNext = link.substr (0, link.length - arrlink[(arrlink.length)-1].length - arrlink[(arrlink.length)-2].length - 1) + actNext + '/' + actNext + '.html';
							document.location = linkNext;
						};
					}
				});
			}
			else {
				$btn.setStyles ({
					'cursor': 'default',
					'background-position': $iB*(-60).toString() + 'px -180px'
				})
			}
		});
	});
};

var reLoad = function () {
	document.location.reload();
};

var activityComplete = function () {
	/*
	var $menuNavigator = $('menuNavigator');
	var $btn5Ani = new Element('div', {
	    'id': 'btn05-ani',
	    'styles': {
	        'opacity': 0
			}
	});

	$btn5Ani.inject($menuNavigator);
	$('btn05').setStyle('background-position', '-300px -180px');
	
	var fxComplete = new Fx.Styles($btn5Ani, {duration:500, wait:false});
	fxComplete.start ({
		opacity: 1
	}).chain(function() {
		fxComplete.start ({
			opacity: 0
		});
		soundManager.play('sndEndAct');
	}).chain(function() {
		$btn5Ani.setStyle('background-position', '-300px -240px');
		fxComplete.start ({
			opacity: 1
		});
	}).chain(function() {
		$('btn05').setStyle('background-position', '-300px top');
		fxComplete.start ({
			opacity: 0
		});
	}).chain(function() {
		$btn5Ani.remove();
	});
	*/
};
var activityCompleteSound = function(seconds){
	seconds=(seconds) ? seconds : 0;
	(function(){soundManager.play('sndEndAct');}).delay(seconds);
};
// Deshabilitamos seleccion de texto
function disableselect(e) {return false}
function reEnable() {return true}
//if IE4+
document.onselectstart=new Function ("return false")
//if NS6
if (window.sidebar) {
   document.onmousedown=disableselect
   document.onclick=reEnable
};
